package com.wzb.mybatisplus.bitaction.electrumaction;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileUtils {

    public static void main(String[] args) {
        FileUtils fileUtils = new FileUtils();
        fileUtils.createFile("D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");
        fileUtils.writeFile("赚钱","D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");
        fileUtils.writeFile("破解","D:\\btc\\miyao\\1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.txt");
    }
    /**
     * 写入文件
     */
    public void  writeFile(String content ,String filePath ){


        try {
            FileWriter writer = new FileWriter(filePath, true); // 使用true参数来表示追加写入
            writer.write(content);
            writer.close();
//            System.out.println("内容已成功追加到文件中。");
            
        } catch (IOException e) {
            System.out.println("追加写入文件时出错：" + e.getMessage());
        }


    }

    /**
     * 创建文件
     * @param filePath
     */
    public void createFile(String filePath){
        // 创建File对象
        File file = new File(filePath);
        try {
            // 创建新文件
            if (file.createNewFile()) {
                System.out.println("文件创建成功：" + file.getAbsolutePath());
            } else {
                System.out.println("文件已存在。");
            }
        } catch (IOException e) {
            System.out.println("发生错误：" + e.getMessage());
        }

    }
}
